﻿using System;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.CompilerServices;

namespace 图片裁剪压缩工具
{
	public class ImageList
	{
		private readonly List<Image> images = new();
		public Image? Reset(Image? image = null)
		{
			images.Clear();
			if (image != null)
			{
				this.images.Add(image);
			}
			return image;
		}
		public Image? Cancel()
		{
			if (images.Count == 0)
			{
				return null;
			}
			else if (images.Count == 1)
			{
				return images[0];
			}
			else
			{
				images.RemoveAt(images.Count - 1);
				return images[images.Count - 1];
			}
		}
		public Image? Add(Image? image)
		{
			if (image == null)
			{
				return null;
			}
			else
			{
				images.Add(image);
				return image;
			}
		}

		public Image? Current => images.Count == 0 ? null : images[images.Count - 1];

		public List<Image> Images => new(images);
		public static void DisposeAll(List<Image> images)
		{
			foreach (Image image in images)
			{
				if (image != null)
				{
					image.Dispose();
				}
			}
		}	
	}
}